import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  { path: '/', redirect: '/index' },
  {
    path: '/index',
    name: 'index',
    component: () => import('../pages/index.vue'),
    redirect: '/wallpaper/36',
    children: [
      { path: '/wallpaper/:id', name: 'wallpaper', component: () => import('../pages/wallpaper/index.vue') },
      // { path: '/wallpaper', name: 'wallpaper', component: () => import('../pages/wallpaper/index.vue') },

      { path: '/photography', name: 'photography', component: () => import('../pages/photography/index.vue') },
    ],
  },
  {
    path: '/music',
    name: 'music',
    component: () => import('../pages/music/index.vue'),
    redirect: '/music/index',
    children: [
      { path: '/music/index', name: 'musicIndex', component: () => import('../pages/music/MusicMain.vue') },
      { path: '/music/play/:id', name: 'musicPlay', component: () => import('../pages/music/MusicPlay.vue') },
      { path: '/music/list/:type/:id', name: 'musicList', component: () => import('../pages/music/MusicList.vue') },
    ],
  },
  {
    path: '/m-music',
    name: 'm-music',
    component: () => import('../pages/m-music/index.vue'),
    redirect: '/m-music/m-home',
    children: [
      { path: '/m-music/m-home', name: 'MmusicHome', component: () => import('../pages/m-music/m-home.vue') },
      { path: '/m-music/m-user', name: 'MmusicUser', component: () => import('../pages/m-music/m-user.vue') },
      { path: '/m-music/search-result', name: 'MSearchResult', component: () => import('../pages/m-music/search-result.vue') },
      { path: '/m-music/play/:id', name: 'MmusicPlay', component: () => import('../pages/m-music/Play.vue') },
      { path: '/m-music/play', name: 'MmusicPlayList', component: () => import('../pages/m-music/Play.vue') },
    ],
  },
  { path: '/navigation', name: 'navigation', component: () => import('../pages/navigation/index.vue') },
  { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('../pages/error.vue') },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  document.title = 'One.'
  next()
})

export default router
